<script setup>
// import { computed } from 'vue'
const props = defineProps({ data: Object })

const avaterPosition = ['旁白', '作者'].includes(props.data.roleName) ? 'right' : 'left'
const isGold = props.data.roleName === '作者'
</script>
<template>
  <div class="message-item">
    <div class="avater avater-left" v-show="avaterPosition === 'left'">
      <i class="iconfont icon-touxiang"></i>
    </div>

    <div :class="{ 'message-box': true, 'is-right': avaterPosition === 'right' }">
      <div class="role-name">
        {{ props.data.roleName }}
      </div>
      <div :class="{ 'message-info': true, 'is-gold': isGold }">
        {{ props.data.messageContent }}
      </div>
    </div>

    <div class="avater avater-right" v-show="avaterPosition === 'right'">
      <i class="iconfont icon-touxiang"></i>
    </div>
  </div>
</template>
<style lang="less" scoped>
.message-item {
  width: 100%;
  margin: 10px 0;
  display: flex;
  .avater {
    > i {
      font-size: 40px;
    }
  }
  .message-box {
    flex: 1;
    .role-name {
      font-size: 18px;
    }
    .message-info {
      color: #fff;
      padding: 10px;
      background-color: green;
      margin-top: 5px;
      max-width: 250px;
      border-radius: 6px;
    }
    .is-gold {
      background-color: red;
    }
  }

  .is-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
  }
}
</style>
